package com.ruoyi.base.service.impl;

import java.time.YearMonth;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

import com.ruoyi.base.po.NamePo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.base.mapper.MHolidaysMapper;
import com.ruoyi.base.domain.MHolidays;
import com.ruoyi.base.service.IMHolidaysService;

/**
 * 员工请假Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-08-09
 */
@Service
public class MHolidaysServiceImpl implements IMHolidaysService 
{
    @Autowired
    private MHolidaysMapper mHolidaysMapper;

    /**
     * 查询员工请假
     * 
     * @param id 员工请假主键
     * @return 员工请假
     */
    @Override
    public MHolidays selectMHolidaysById(Long id)
    {
        return mHolidaysMapper.selectMHolidaysById(id);
    }

    /**
     * 查询员工请假列表
     * 
     * @param mHolidays 员工请假
     * @return 员工请假
     */
    @Override
    public List<MHolidays> selectMHolidaysList(MHolidays mHolidays)
    {
        return mHolidaysMapper.selectMHolidaysList(mHolidays);
    }

    /**
     * 新增员工请假
     * 
     * @param mHolidays 员工请假
     * @return 结果
     */
    @Override
    public int insertMHolidays(MHolidays mHolidays)
    {
        //设置请假月
        int month= mHolidays.getStartTime().getMonth();
        String Hmonth= month+1+"月";
        mHolidays.setHolidayMonth(Hmonth);

        //设置请假天数
        Long day= (Long) ((mHolidays.getEndTime().getTime()-mHolidays.getStartTime().getTime())/(1000*3600*24)+1);
        mHolidays.sethDays(day);

        //设置姓名
        mHolidays.setsName(mHolidaysMapper.selectName(mHolidays.getsId()));
        return mHolidaysMapper.insertMHolidays(mHolidays);
    }

    /**
     * 修改员工请假
     * 
     * @param mHolidays 员工请假
     * @return 结果
     */
    @Override
    public int updateMHolidays(MHolidays mHolidays)
    {
        return mHolidaysMapper.updateMHolidays(mHolidays);
    }

    /**
     * 批量删除员工请假
     * 
     * @param ids 需要删除的员工请假主键
     * @return 结果
     */
    @Override
    public int deleteMHolidaysByIds(Long[] ids)
    {
        return mHolidaysMapper.deleteMHolidaysByIds(ids);
    }

    /**
     * 删除员工请假信息
     * 
     * @param id 员工请假主键
     * @return 结果
     */
    @Override
    public int deleteMHolidaysById(Long id)
    {
        return mHolidaysMapper.deleteMHolidaysById(id);
    }

    @Override
    public List<NamePo> selectNameList() {
        return mHolidaysMapper.selectNameList();
    }
}
